<?php

namespace app\admin\controller;

use app\admin\common\Common;
use think\Controller;
use think\Db;
use think\db\exception\DataNotFoundException;
use think\db\exception\ModelNotFoundException;
use think\exception\DbException;
use think\facade\Session;

class LoginThere extends Controller
{
    public function __construct()
    {
        try {
            $admin = Db::name('admin')->where('id', 1)->find();
        } catch (DataNotFoundException $e) {
            return Common::result(400,$e->getMessage());
        } catch (ModelNotFoundException $e) {
            return Common::result(400,$e->getMessage());
        } catch (DbException $e) {
            return Common::result(400,$e->getMessage());
        }
        $admintoken = Session::get('admintoken');
        if ($admintoken == null){
            return $this->error('登录已失效,请重新登录！','login/');
        }else{
            if (md5($admin['password'].$admin['salt']) != $admintoken){
                return $this->error('你的账号已在别处登录，请重新登录账号','login/');
            }
        }
    }

}